Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Response body for post #484

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

VivekHub97
Copy link
Contributor

@VivekHub97 VivekHub97 commented Oct 8, 2024

fix: Response body for posting in submodel repository and submodel service

Closes #398
Closes #457

Copy link
Contributor

@mdanish98 mdanish98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @VivekHub97 ,

Thanks a lot for the implementation.

Actually, this should be fixed in core [1] and [2] first and then at the Controller side, the return type here in [1] and [2] is void but it should be SubmodelElement, and then at the HttpController [3] and [4] respectively for Repo and Service, it should be like below:

@Override
public ResponseEntity<SubmodelElement> postSubmodelElementSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, @Valid SubmodelElement body) {
    SubmodelElement createdSME = repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body);
    return new ResponseEntity<SubmodelElement>(createdSME, HttpStatus.CREATED);
}

Inside SubmodelRepoHttpController [3] the method postSubmodelElementByPathSubmodelRepo is not fixed.

Following is the summary:

  • Update interfaces of SubmodelRepository [1] and SubmodelService [2] for createSubmodelElement methods (there are multiple overloaded methods) such that the return type is SME instead of void.
  • Then handle this appropriately wherever these interfaces are implemented possibly in all implementations (Crud*Repo) and all features.
  • Update HTTP controllers for SMRepo [3] and SMService [4] like I defined above
  • Update the test cases to additionally check the creation response wherever required. (Maybe do this first to achieve Test Driven Development).

[1] basyx-java-server-sdk/basyx.submodelrepository/basyx.submodelrepository-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/SubmodelRepository.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
[2] basyx-java-server-sdk/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
[3] basyx-java-server-sdk/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
[4] basyx-java-server-sdk/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)

Copy link
Contributor

@mdanish98 mdanish98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no tests in the SubmodelServiceSuite. Please add them as well.

Comment on lines 200 to 207
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) {
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId);

submodelService.createSubmodelElement(smElement);

updateSubmodel(submodelId, submodelService.getSubmodel());
return smElement;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) {
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId);
submodelService.createSubmodelElement(smElement);
updateSubmodel(submodelId, submodelService.getSubmodel());
return smElement;
}
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) {
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId);
SubmodelElement createdSME = submodelService.createSubmodelElement(smElement);
updateSubmodel(submodelId, submodelService.getSubmodel());
return createdSME;
}

Comment on lines 210 to 217
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException {
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId);

submodelService.createSubmodelElement(idShortPath, smElement);

updateSubmodel(submodelId, submodelService.getSubmodel());
return smElement;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException {
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId);
submodelService.createSubmodelElement(idShortPath, smElement);
updateSubmodel(submodelId, submodelService.getSubmodel());
return smElement;
}
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException {
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId);
SubmodelElement createdSME = submodelService.createSubmodelElement(idShortPath, smElement);
updateSubmodel(submodelId, submodelService.getSubmodel());
return createdSME;
}

@@ -99,17 +99,19 @@ public void setSubmodelElementValue(String submodelId, String idShortPath, Submo
}

@Override
public void createSubmodelElement(String submodelId, SubmodelElement smElement) {
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) {
decorated.createSubmodelElement(submodelId, smElement);
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, smElement.getIdShort());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we can get rid of this getSME operation and use the createSME return.

Suggested change
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, smElement.getIdShort());
SubmodelElement submodelElement = decorated.createSubmodelElement(submodelId, smElement);

}

@Override
public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException {
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException {
decorated.createSubmodelElement(submodelId, idShortPath, smElement);
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, idShortPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


assertEquals(responseSubmodelElement, submodelElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected should be first parameter.

Suggested change
assertEquals(responseSubmodelElement, submodelElement);
assertEquals(submodelElement, responseSubmodelElement);

InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService();
inMemorySubmodelService.createSubmodelElement(submodelElement);
Submodel submodel = inMemorySubmodelService.getSubmodel();
crudRepository.save(submodel);
return submodelElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the returned SME from line 108 and not return the SME received as a parameter.

InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService();
inMemorySubmodelService.createSubmodelElement(idShortPath, submodelElement);
Submodel submodel = inMemorySubmodelService.getSubmodel();
crudRepository.save(submodel);
return submodelElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@@ -718,6 +718,10 @@ private DefaultEntity createDummyEntityWithStatement(SubmodelElement submodelEle
private DefaultProperty createDummyProperty(String idShort) {
return new DefaultProperty.Builder().idShort(idShort).category("cat1").value("123").valueType(DataTypeDefXsd.INTEGER).build();
}

private SubmodelElement createDummySME(String idShort) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain the need of this? Because I can't find any reference to this private method in this class.

@@ -93,19 +93,21 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val
}

@Override
public void createSubmodelElement(SubmodelElement submodelElement) {
public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) {
decorated.createSubmodelElement(submodelElement);
SubmodelElement smElement = decorated.getSubmodelElement(submodelElement.getIdShort());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this method and use the returned SME from line 97

}

@Override
public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException {
public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException {

decorated.createSubmodelElement(idShortPath, submodelElement);

SubmodelElement smElement = decorated.getSubmodelElement(submodelElement.getIdShort());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants